import java.util.ArrayList;
import java.util.List;

public class Student {
    private String studentId;       // 学生编号
    private String studentName;     // 学生姓名
    private String gender;          // 性别
    private String grade;           // 年级
    private List<Course> selectedCourses; // 所选课程列表
    public Student(String studentId, String studentName, String gender, String grade) {
        this.studentId = studentId;
        this.studentName = studentName;
        this.gender = gender;
        this.grade = grade;
        this.selectedCourses = new ArrayList<>(); // 初始化
    }
    //学生选课
    public void selectCourse(Course course) {
        if (!selectedCourses.contains(course)) {
            selectedCourses.add(course);
            System.out.println("【选课成功】学生" + studentName + gender + "生" + "（" + grade + "）选修课程：" + course.getCourseName());
        } else {
            System.out.println("【选课失败】学生" + studentName + "已选修该课程");
        }
    }
    //学生退课
    public void dropCourse(Course course) {
        if (selectedCourses.contains(course)) {
            selectedCourses.remove(course);
            System.out.println("【退课成功】学生" + studentName + "退选课程：" + course.getCourseName());
        } else {
            System.out.println("【退课失败】学生" + studentName + "未选修该课程");
        }
    }
    //学生课表
    public void printSchedule(List<Teacher> teacherList) {
        System.out.println("\n=== " + studentName + "（学号：" + studentId + "）的课表 ===");
        System.out.printf("%-8s%-12s%-10s%-12s%-6s%-8s\n", "课程编号", "课程名称", "上课教室", "上课时间", "学分", "授课教师");
        
        for (Course course : selectedCourses) {
            String teacherName = "未分配教师";
            for (Teacher teacher : teacherList) {
                if (teacher.getTeacherId().equals(course.getTeacherId())) {
                    teacherName = teacher.getTeacherName();
                    break;
                }
            }
            //输出课表
            System.out.printf("%-8s%-12s%-10s%-12s%-6d%-8s\n", 
                course.getCourseId(),
                course.getCourseName(),
                course.getClassRoom(),
                course.getCourseTime(),
                course.getCredit(),
                teacherName);
        }
    }
    public String getStudentId() { return studentId; }
    public String getStudentName() { return studentName; }
    public List<Course> getSelectedCourses() { return selectedCourses; }
}